using Microsoft.VisualBasic.CompilerServices;
using System;
using System.Collections;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Runtime.CompilerServices;
using System.Windows.Forms;
using yW5Lib;

namespace yWriter6
{
	[DesignerGenerated]
	public class frmEditVariables : Form
	{
		private IContainer components;

		[CompilerGenerated]
		[AccessedThroughProperty("ListVar")]
		private ListBox _ListVar;

		[CompilerGenerated]
		[AccessedThroughProperty("Label1")]
		private Label _Label1;

		[CompilerGenerated]
		[AccessedThroughProperty("txtVariable")]
		private TextBox _txtVariable;

		[CompilerGenerated]
		[AccessedThroughProperty("Label2")]
		private Label _Label2;

		[CompilerGenerated]
		[AccessedThroughProperty("cmdAddUpdate")]
		private Button _cmdAddUpdate;

		[CompilerGenerated]
		[AccessedThroughProperty("cmdDelete")]
		private Button _cmdDelete;

		[CompilerGenerated]
		[AccessedThroughProperty("cmdCancel")]
		private Button _cmdCancel;

		[CompilerGenerated]
		[AccessedThroughProperty("cmdOkay")]
		private Button _cmdOkay;

		[CompilerGenerated]
		[AccessedThroughProperty("txtValue")]
		private RichTextBox _txtValue;

		[CompilerGenerated]
		[AccessedThroughProperty("Label4")]
		private Label _Label4;

		[CompilerGenerated]
		[AccessedThroughProperty("chkConditional")]
		private CheckBox _chkConditional;

		[CompilerGenerated]
		[AccessedThroughProperty("cmbCond")]
		private ComboBox _cmbCond;

		[CompilerGenerated]
		[AccessedThroughProperty("ToolTip1")]
		private ToolTip _ToolTip1;

		[CompilerGenerated]
		[AccessedThroughProperty("Label3")]
		private Label _Label3;

		private clsVars cVars;

		internal virtual ListBox ListVar
		{
			[CompilerGenerated]
			get
			{
				return _ListVar;
			}
			[MethodImpl(MethodImplOptions.Synchronized)]
			[CompilerGenerated]
			set
			{
				EventHandler value2 = ListVar_SelectedIndexChanged;
				ListBox listVar = _ListVar;
				if (listVar != null)
				{
					listVar.SelectedIndexChanged -= value2;
				}
				_ListVar = value;
				listVar = _ListVar;
				if (listVar != null)
				{
					listVar.SelectedIndexChanged += value2;
				}
			}
		}

		[field: AccessedThroughProperty("Label1")]
		internal virtual Label Label1
		{
			get;
			[MethodImpl(MethodImplOptions.Synchronized)]
			set;
		}

		[field: AccessedThroughProperty("txtVariable")]
		internal virtual TextBox txtVariable
		{
			get;
			[MethodImpl(MethodImplOptions.Synchronized)]
			set;
		}

		[field: AccessedThroughProperty("Label2")]
		internal virtual Label Label2
		{
			get;
			[MethodImpl(MethodImplOptions.Synchronized)]
			set;
		}

		internal virtual Button cmdAddUpdate
		{
			[CompilerGenerated]
			get
			{
				return _cmdAddUpdate;
			}
			[MethodImpl(MethodImplOptions.Synchronized)]
			[CompilerGenerated]
			set
			{
				EventHandler value2 = cmdAddUpdate_Click;
				Button cmdAddUpdate = _cmdAddUpdate;
				if (cmdAddUpdate != null)
				{
					cmdAddUpdate.Click -= value2;
				}
				_cmdAddUpdate = value;
				cmdAddUpdate = _cmdAddUpdate;
				if (cmdAddUpdate != null)
				{
					cmdAddUpdate.Click += value2;
				}
			}
		}

		internal virtual Button cmdDelete
		{
			[CompilerGenerated]
			get
			{
				return _cmdDelete;
			}
			[MethodImpl(MethodImplOptions.Synchronized)]
			[CompilerGenerated]
			set
			{
				EventHandler value2 = cmdDelete_Click;
				Button cmdDelete = _cmdDelete;
				if (cmdDelete != null)
				{
					cmdDelete.Click -= value2;
				}
				_cmdDelete = value;
				cmdDelete = _cmdDelete;
				if (cmdDelete != null)
				{
					cmdDelete.Click += value2;
				}
			}
		}

		internal virtual Button cmdCancel
		{
			[CompilerGenerated]
			get
			{
				return _cmdCancel;
			}
			[MethodImpl(MethodImplOptions.Synchronized)]
			[CompilerGenerated]
			set
			{
				EventHandler value2 = cmdCancel_Click;
				Button cmdCancel = _cmdCancel;
				if (cmdCancel != null)
				{
					cmdCancel.Click -= value2;
				}
				_cmdCancel = value;
				cmdCancel = _cmdCancel;
				if (cmdCancel != null)
				{
					cmdCancel.Click += value2;
				}
			}
		}

		internal virtual Button cmdOkay
		{
			[CompilerGenerated]
			get
			{
				return _cmdOkay;
			}
			[MethodImpl(MethodImplOptions.Synchronized)]
			[CompilerGenerated]
			set
			{
				EventHandler value2 = cmdOkay_Click;
				Button cmdOkay = _cmdOkay;
				if (cmdOkay != null)
				{
					cmdOkay.Click -= value2;
				}
				_cmdOkay = value;
				cmdOkay = _cmdOkay;
				if (cmdOkay != null)
				{
					cmdOkay.Click += value2;
				}
			}
		}

		internal virtual RichTextBox txtValue
		{
			[CompilerGenerated]
			get
			{
				return _txtValue;
			}
			[MethodImpl(MethodImplOptions.Synchronized)]
			[CompilerGenerated]
			set
			{
				EventHandler value2 = txtValue_TextChanged;
				RichTextBox txtValue = _txtValue;
				if (txtValue != null)
				{
					txtValue.TextChanged -= value2;
				}
				_txtValue = value;
				txtValue = _txtValue;
				if (txtValue != null)
				{
					txtValue.TextChanged += value2;
				}
			}
		}

		internal virtual Label Label4
		{
			[CompilerGenerated]
			get
			{
				return _Label4;
			}
			[MethodImpl(MethodImplOptions.Synchronized)]
			[CompilerGenerated]
			set
			{
				EventHandler value2 = Label3_Click;
				Label label = _Label4;
				if (label != null)
				{
					label.Click -= value2;
				}
				_Label4 = value;
				label = _Label4;
				if (label != null)
				{
					label.Click += value2;
				}
			}
		}

		internal virtual CheckBox chkConditional
		{
			[CompilerGenerated]
			get
			{
				return _chkConditional;
			}
			[MethodImpl(MethodImplOptions.Synchronized)]
			[CompilerGenerated]
			set
			{
				EventHandler value2 = chkConditional_CheckedChanged;
				CheckBox chkConditional = _chkConditional;
				if (chkConditional != null)
				{
					chkConditional.CheckedChanged -= value2;
				}
				_chkConditional = value;
				chkConditional = _chkConditional;
				if (chkConditional != null)
				{
					chkConditional.CheckedChanged += value2;
				}
			}
		}

		[field: AccessedThroughProperty("cmbCond")]
		internal virtual ComboBox cmbCond
		{
			get;
			[MethodImpl(MethodImplOptions.Synchronized)]
			set;
		}

		[field: AccessedThroughProperty("ToolTip1")]
		internal virtual ToolTip ToolTip1
		{
			get;
			[MethodImpl(MethodImplOptions.Synchronized)]
			set;
		}

		[field: AccessedThroughProperty("Label3")]
		internal virtual Label Label3
		{
			get;
			[MethodImpl(MethodImplOptions.Synchronized)]
			set;
		}

		public frmEditVariables()
		{
			base.Load += frmVar_Load;
			InitializeComponent();
		}

		[DebuggerNonUserCode]
		protected override void Dispose(bool disposing)
		{
			try
			{
				if (disposing && components != null)
				{
					components.Dispose();
				}
			}
			finally
			{
				base.Dispose(disposing);
			}
		}

		[System.Diagnostics.DebuggerStepThrough]
		private void InitializeComponent()
		{
			components = new System.ComponentModel.Container();
			ListVar = new System.Windows.Forms.ListBox();
			Label1 = new System.Windows.Forms.Label();
			txtVariable = new System.Windows.Forms.TextBox();
			Label2 = new System.Windows.Forms.Label();
			cmdAddUpdate = new System.Windows.Forms.Button();
			cmdDelete = new System.Windows.Forms.Button();
			cmdCancel = new System.Windows.Forms.Button();
			cmdOkay = new System.Windows.Forms.Button();
			txtValue = new System.Windows.Forms.RichTextBox();
			Label4 = new System.Windows.Forms.Label();
			chkConditional = new System.Windows.Forms.CheckBox();
			cmbCond = new System.Windows.Forms.ComboBox();
			ToolTip1 = new System.Windows.Forms.ToolTip(components);
			Label3 = new System.Windows.Forms.Label();
			SuspendLayout();
			ListVar.FormattingEnabled = true;
			ListVar.ItemHeight = 17;
			ListVar.Location = new System.Drawing.Point(11, 64);
			ListVar.Margin = new System.Windows.Forms.Padding(2, 3, 2, 3);
			ListVar.Name = "ListVar";
			ListVar.Size = new System.Drawing.Size(177, 429);
			ListVar.TabIndex = 1;
			Label1.AutoSize = true;
			Label1.Location = new System.Drawing.Point(193, 64);
			Label1.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
			Label1.Name = "Label1";
			Label1.Size = new System.Drawing.Size(100, 19);
			Label1.TabIndex = 2;
			Label1.Text = "Variable Name:";
			Label1.TextAlign = System.Drawing.ContentAlignment.TopRight;
			txtVariable.Location = new System.Drawing.Point(303, 64);
			txtVariable.Margin = new System.Windows.Forms.Padding(2, 3, 2, 3);
			txtVariable.Name = "txtVariable";
			txtVariable.Size = new System.Drawing.Size(168, 25);
			txtVariable.TabIndex = 3;
			Label2.AutoSize = true;
			Label2.Location = new System.Drawing.Point(219, 173);
			Label2.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
			Label2.Name = "Label2";
			Label2.Size = new System.Drawing.Size(74, 19);
			Label2.TabIndex = 2;
			Label2.Text = "Value/Text:";
			Label2.TextAlign = System.Drawing.ContentAlignment.TopRight;
			cmdAddUpdate.Location = new System.Drawing.Point(486, 59);
			cmdAddUpdate.Margin = new System.Windows.Forms.Padding(2, 3, 2, 3);
			cmdAddUpdate.Name = "cmdAddUpdate";
			cmdAddUpdate.Size = new System.Drawing.Size(117, 35);
			cmdAddUpdate.TabIndex = 4;
			cmdAddUpdate.Text = "Add/Update";
			cmdAddUpdate.UseVisualStyleBackColor = true;
			cmdDelete.Location = new System.Drawing.Point(203, 429);
			cmdDelete.Margin = new System.Windows.Forms.Padding(2, 3, 2, 3);
			cmdDelete.Name = "cmdDelete";
			cmdDelete.Size = new System.Drawing.Size(82, 64);
			cmdDelete.TabIndex = 5;
			cmdDelete.Text = "Delete Selected";
			cmdDelete.UseVisualStyleBackColor = true;
			cmdCancel.Location = new System.Drawing.Point(11, 500);
			cmdCancel.Margin = new System.Windows.Forms.Padding(2, 3, 2, 3);
			cmdCancel.Name = "cmdCancel";
			cmdCancel.Size = new System.Drawing.Size(65, 39);
			cmdCancel.TabIndex = 6;
			cmdCancel.Text = "Cancel";
			cmdCancel.UseVisualStyleBackColor = true;
			cmdOkay.Location = new System.Drawing.Point(538, 500);
			cmdOkay.Margin = new System.Windows.Forms.Padding(2, 3, 2, 3);
			cmdOkay.Name = "cmdOkay";
			cmdOkay.Size = new System.Drawing.Size(65, 39);
			cmdOkay.TabIndex = 6;
			cmdOkay.Text = "Okay";
			cmdOkay.UseVisualStyleBackColor = true;
			txtValue.Location = new System.Drawing.Point(303, 170);
			txtValue.Margin = new System.Windows.Forms.Padding(2, 3, 2, 3);
			txtValue.Name = "txtValue";
			txtValue.Size = new System.Drawing.Size(300, 323);
			txtValue.TabIndex = 7;
			txtValue.Text = "";
			Label4.AutoSize = true;
			Label4.Location = new System.Drawing.Point(221, 135);
			Label4.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
			Label4.Name = "Label4";
			Label4.Size = new System.Drawing.Size(72, 19);
			Label4.TabIndex = 2;
			Label4.Text = "Condition:";
			Label4.TextAlign = System.Drawing.ContentAlignment.TopRight;
			chkConditional.AutoSize = true;
			chkConditional.CheckAlign = System.Drawing.ContentAlignment.MiddleRight;
			chkConditional.Location = new System.Drawing.Point(213, 98);
			chkConditional.Name = "chkConditional";
			chkConditional.Size = new System.Drawing.Size(98, 23);
			chkConditional.TabIndex = 8;
			chkConditional.Text = "Conditional";
			chkConditional.UseVisualStyleBackColor = true;
			cmbCond.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
			cmbCond.FormattingEnabled = true;
			cmbCond.Location = new System.Drawing.Point(303, 129);
			cmbCond.Name = "cmbCond";
			cmbCond.Size = new System.Drawing.Size(298, 25);
			cmbCond.TabIndex = 9;
			ToolTip1.ToolTipTitle = "You can include project level vars inside global vars.";
			Label3.Location = new System.Drawing.Point(12, 9);
			Label3.Name = "Label3";
			Label3.Size = new System.Drawing.Size(576, 32);
			Label3.TabIndex = 10;
			Label3.Text = "Global variables can contain project variables (define in value/text with [varname])";
			base.AutoScaleDimensions = new System.Drawing.SizeF(7f, 17f);
			base.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
			base.ClientSize = new System.Drawing.Size(612, 550);
			base.Controls.Add(Label3);
			base.Controls.Add(cmbCond);
			base.Controls.Add(chkConditional);
			base.Controls.Add(txtValue);
			base.Controls.Add(cmdOkay);
			base.Controls.Add(cmdCancel);
			base.Controls.Add(cmdDelete);
			base.Controls.Add(cmdAddUpdate);
			base.Controls.Add(txtVariable);
			base.Controls.Add(Label4);
			base.Controls.Add(Label2);
			base.Controls.Add(Label1);
			base.Controls.Add(ListVar);
			Font = new System.Drawing.Font("Segoe UI", 10f);
			base.Margin = new System.Windows.Forms.Padding(2, 3, 2, 3);
			base.Name = "frmEditVariables";
			Text = "Variables";
			ResumeLayout(false);
			PerformLayout();
		}

		public void DisplayVar(clsVars VarClass, string Title)
		{
			Text = Title;
			cVars = VarClass;
			FillList();
		}

		private void FillList()
		{
			ListVar.Items.Clear();
			IEnumerator enumerator = default(IEnumerator);
			try
			{
				enumerator = cVars.GetEnumerator();
				while (enumerator.MoveNext())
				{
					clsVar item = (clsVar)enumerator.Current;
					ListVar.Items.Add(item);
				}
			}
			finally
			{
				if (enumerator is IDisposable)
				{
					(enumerator as IDisposable).Dispose();
				}
			}
			cmbCond.Items.Clear();
			cmbCond.Items.Add("N/A");
			cmbCond.Items.Add("Only for custom exports");
			cmbCond.Items.Add("Only when exporting to ebook");
			cmbCond.Items.Add("Only when exporting to LaTeX");
			cmbCond.Items.Add("Only when exporting to Html");
			cmbCond.Items.Add("Only when exporting to Rtf");
		}

		private void ListVar_SelectedIndexChanged(object sender, EventArgs e)
		{
			try
			{
				clsVar clsVar = (clsVar)ListVar.SelectedItem;
				txtVariable.Text = clsVar.Title;
				try
				{
					txtValue.Rtf = clsVar.DescText;
				}
				catch (Exception ex)
				{
					ProjectData.SetProjectError(ex);
					Exception ex2 = ex;
					txtValue.Text = clsVar.DescText;
					ProjectData.ClearProjectError();
				}
				if (Operators.CompareString(clsVar.Tags, "1", TextCompare: false) == 0)
				{
					chkConditional.Checked = true;
					int num = cmbCond.FindStringExact(clsVar.AKA);
					if (num >= 0)
					{
						cmbCond.SelectedIndex = num;
					}
				}
				else
				{
					chkConditional.Checked = false;
				}
			}
			catch (Exception ex3)
			{
				ProjectData.SetProjectError(ex3);
				Exception ex4 = ex3;
				ProjectData.ClearProjectError();
			}
		}

		private void cmdAddUpdate_Click(object sender, EventArgs e)
		{
			AddUpdate();
		}

		private void AddUpdate()
		{
			if (Operators.CompareString(txtVariable.Text.Trim(), "", TextCompare: false) == 0)
			{
				return;
			}
			IEnumerator enumerator = default(IEnumerator);
			bool flag = default(bool);
			try
			{
				enumerator = ListVar.Items.GetEnumerator();
				while (enumerator.MoveNext())
				{
					clsVar cVar = (clsVar)enumerator.Current;
					if (Operators.CompareString(cVar.Title, txtVariable.Text, TextCompare: false) == 0)
					{
						SaveVar(ref cVar);
						flag = true;
					}
				}
			}
			finally
			{
				if (enumerator is IDisposable)
				{
					(enumerator as IDisposable).Dispose();
				}
			}
			if (!flag)
			{
				clsVar cVar2 = new clsVar();
				cVar2.Title = txtVariable.Text;
				SaveVar(ref cVar2);
				if (cVars.Added(ref cVar2))
				{
					ListVar.Items.Add(cVar2);
				}
			}
		}

		private void SaveVar(ref clsVar cVar)
		{
			cVar.DescText = txtValue.Rtf;
			if (chkConditional.Checked)
			{
				cVar.Tags = "1";
			}
			else
			{
				cVar.Tags = "0";
			}
			cVar.AKA = cmbCond.Text;
		}

		private void frmVar_Load(object sender, EventArgs e)
		{
			ListVar.DisplayMember = "Title";
			ListVar.Sorted = true;
		}

		private void cmdDelete_Click(object sender, EventArgs e)
		{
			int num = ListVar.SelectedItems.Count - 1;
			for (int i = 0; i <= num; i++)
			{
				clsVar clsVar = (clsVar)ListVar.SelectedItems[i];
				cVars.RemoveByID(clsVar.ID);
			}
			FillList();
		}

		private void cmdOkay_Click(object sender, EventArgs e)
		{
			AddUpdate();
			Hide();
		}

		private void cmdCancel_Click(object sender, EventArgs e)
		{
			Hide();
		}

		private void txtValue_TextChanged(object sender, EventArgs e)
		{
		}

		private void Label3_Click(object sender, EventArgs e)
		{
		}

		private void chkConditional_CheckedChanged(object sender, EventArgs e)
		{
			if (chkConditional.Checked)
			{
				cmbCond.Enabled = true;
			}
			else
			{
				cmbCond.Enabled = false;
			}
		}
	}
}
